package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.NoticeDao;
import com.ChenYaRou.www.po.Notice;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName NoticeDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 22:10
 * @Version 1.0
 **/
public class NoticeDaoImpl implements NoticeDao {
    /**
     * 查找系统通知集合
     * @param notice 仅赋值条件的系统通知
     * @return 系统通知集合
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<Notice> select(Notice notice) throws IllegalAccessException, SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().select(notice), Notice.class);
    }

    /**
     * update notice
     * @param newNotice notice要更新的值
     * @param  oldNotice old notice
     * @return 成功与否
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(Notice newNotice, Notice oldNotice) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newNotice,oldNotice));

    }
    /**
     * 插入notice
     * @param notice 新notice
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(Notice notice) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(notice));
    }
}
